<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
 	<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <div class="ibox-title" style="border-color: white;">
                    <div class="row">
                        <div class="col-sm-3" style="width: 100%;">
                            <div class="input-group" style="width: 100%;">
                                <input id="name" type="text" placeholder="请输入沟通名称" class="input-sm form-control" style="width: 15%;">
                                <input type="hidden" id="recommendId" value="${recommend.id }" />
                                <input type="hidden" id="companyId" value="${recommend.companyId }" />
                                <input type="hidden" id="recommendIsPast" value="${recommend.isPast }" />
                                <input type="hidden" id="talentsId" value="${talentsId }" />
                                <input type="hidden" id="workId" value="${workId }" />
                                <span class="input-group-btn"  style="float: left;">
                                        <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a> </span>
	                            <%-- <s:hasPermission name="demandCommunicate:add">
	                            	 <span class="input-group-btn" style="float: left; margin-left: 25px;">
	                             		<a  class="btn btn-sm btn-success" style="margin-left: 20px;" onclick="showadd();"> 添加</a>
	                             	 </span>
	                            </s:hasPermission> --%>
                             </div>
                        </div>
                    </div>
                </div>
                <!-- biaogebigin -->
                <div class="ibox-content" style=" padding-left: 0px; margin-top: 10px;">
                    <div class="jqGrid_wrapper">
                        <table id="table_list"></table>
                        <div id="pager_list"></div>
                    </div>
                </div>
                <!-- tableover -->
            </div>
            <!-- PAGE CONTENT ENDS HERE -->

        </div>
        <!--/row-->
    </div>
    <!--/#page-content-->
</div>
<!--/.fluid-container#main-container-->
<script type="text/javascript">
    var recommend_id = $("#recommendId").val();
    var recommend_ispast = $("#recommendIsPast").val();
    var talents_id = $("#talentsId").val();
    var company_id = $("#companyId").val();
    var work_id = $("#workId").val();  
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#table_list").jqGrid({
            url: '<%=contextPath%>/demandCommunicate/listData',
            datatype: "json",
            postData: {'recommendId':recommend_id,'talentsId':talents_id,'workId':work_id}, //发送数据
            autowidth: true,
            rownumbers: true,
            shrinkToFit: true,
            mtype: "post",
            sortname: 'communicationTime',
            sortorder: "desc",
            rowNum: 10,
            rowList: [10, 20, 30],
            colNames: [
			"id",
			"所属简历",
			"沟通事项",
			"沟通方式",
			"沟通目的",
			"沟通内容",
			" 沟通人 ",
			"沟通时间",
			"下次沟通",
			"是否通过", 
			"面试情况",
	        "操作"],
            colModel: [
			{name: "id",index: "id",hidden: true}, 
				{name:"resume.trueName",index:"resume.trueName",width:80},
				{name:"dictClass",index:"dictClass",width:80},
				{name:"methods",index:"methods",width:100},
				{name:"purpose",index:"purpose",width:100},
				{name:"details",index:"details",width:100},
				{name:"user.truename",index:"user.truename",width:80},
				{name:"communicationTime",index:"communicationTime",width:100},
				{name:"nextTime",index:"nextTime",width:100},
                {name:"isPast",index:"isPast",width:80,
					formatter: function (value, options, row) {
						var htm="";
						if(value == 0){
							htm = "<span class='label label-default'>未反馈</span>";
						}else if(value == 1){
							htm = "<span class='label label-success'>是</span>";
						}else if(value == 2){
							htm = "<span class='label label-danger'>否</span>";
						}
						return htm;
					}
				},{
					formatter: function (value, options, row) {
						var htm='<a onclick="openrecord(&quot;'+row.id+'&quot;);" class="btm-sm btn-link">查看详请</a>';
						return htm;
					},
					width: 80
				},
				{
	                formatter: function (cellvalue, options, row) {
	                	var htm="";
	                	if(recommend_ispast != 2){
	                		if(row.isPast != 2){
	                			if(row.classid == 2 || row.classid == 3 || row.classid == 4 ){
	                				htm+="  <a class='btn btn-sm btn-primary' title='面试反馈' onclick='addfeedback(&quot;" + row.id + "&quot;,&quot;" + recommend_id + "&quot;)'><i class='icon-ok'></i></a>";
	                			}
	                			if(row.classid == 5 ){
	                				htm+="  <a class='btn btn-sm btn-primary' title='背调反馈' onclick='addsurvey(&quot;" + row.id + "&quot;,&quot;" + recommend_id + "&quot;)'><i class='icon-ok'></i></a>";
	                			}
	                			if(row.classid == 6 ){
	                				htm+="  <a class='btn btn-sm btn-primary' title='添加offer' onclick='addoffer(&quot;" + row.id + "&quot;,&quot;" + recommend_id + "&quot;)'><i class='icon-plus'></i></a>";
	                			}
	                			if(row.classid == 7 ){
	                				htm+="  <a class='btn btn-sm btn-primary' title='入职反馈' onclick='addentry(&quot;" + row.id + "&quot;,&quot;" + recommend_id + "&quot;)'><i class='icon-ok-sign'></i></a>";
	                			}
	                			if(row.classid == 7 || row.classid == 9){
	                				htm+="  <a class='btn btn-sm btn-primary' title='开票' onclick='addinvoice(&quot;" + row.id + "&quot;,&quot;" + row.projectId + "&quot;,&quot;" + row.telentsId + "&quot;)'><i class='icon-credit-card'></i></a>";
	                			}
	                		}
	                		if(row.isPast == 0){
	                		htm+="  <a class='btn btn-sm btn-primary' title='沟通结果' onclick='addresult(&quot;" + row.id + "&quot;,&quot;"+recommend_id+"&quot;,&quot;"+row.companyId+"&quot;,&quot;"+row.projectId+"&quot;,&quot;"+talents_id+"&quot;)'><i class='icon-check'></i></a>";
	                		}
	                	}
	                    return htm;
	                },
                width: 150
            }],
            height: $(window).height() - 170,
            pager: "#pager_list",
            //multiselect: true,//多选按钮
            //multiboxonly: true,
            viewrecords: true,
            hidegrid: false
        });
        //表格自适应高宽
        $(window).bind("resize", function () {
            var b = $(".jqGrid_wrapper").width();
            $("#table_list").setGridWidth(b);
            $("#table_list").setGridHeight($(window).height() - 170);
        })
        $("#table_list").navGrid('#pager_list', {edit: false, add: false, del: false, search: false})
        /* 判断是否有添加权限 */
        //检索
        $("#find_btn").click(function () {
            var name = $("#name").val();
            $("#table_list").jqGrid('setGridParam', {
                postData: {
                	'name': name,
                	'recommendId':recommend_id,
                	'talentsId':talents_id
                	}, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });

        function addfeedback(id,recommendId) {
    		swal({ 
    			title: "是否参加面试？", 
    			type: "warning", 
    			showCancelButton: true, 
    			confirmButtonColor: "#DD6B55", 
    			confirmButtonText: "No", 
    			cancelButtonText: "Yes", 
    			closeOnConfirm: false, 
    			closeOnCancel: false 
    			}, 
    			function(isConfirm) { 
    				if (isConfirm) { 
    					swal({
    	       		    	title:"请填写",
    	       		    	type: "input",
    	       		    	showCancelButton: true, 
    	       			    closeOnConfirm: false, 
    	       			    cancelButtonText: "取消", 
    	       			    confirmButtonText: "确认",
    	       		    	inputPlaceholder: "请填写未参加原因",
    	       		    	showLoaderOnConfirm: true
    	       		    },function(inputValue){ 
    	       				if(inputValue === false){
    	       					return false
    	       				}else {
    	       					if (inputValue === "") { 
    	       						swal.showInputError("请填写未参加原因");
    	       					    return false 
    	       					}else{
    	       						$.ajax({
    	       							url: '<%=contextPath%>/demandInterview/updateStatus',
    	       							data:{
    	       								'status':2,
    	       								'communicateId':id,
    	       								'recommendId':recommendId,
    	       								'reason':inputValue
    	       								},
    	       			                type: 'post',
    	       			                dataType: "json",
    	       			                beforeSend: function () {
    	       						        // 禁用按钮防止重复提交
    	       								swal("信息已经提交，请等待后台处理~！");
    	       						    },
    	       							success : function(data) {
    	       								if (data.code == 200) {
    	       									swal({
    	       										title : data.message,
    	       										type : "success",
    	       										showCancelButton : false,
    	       										confirmButtonText : "确定",
    	       										animation : "slide-from-bottom",
    	       										text: "2秒后自动关闭。", 
    	       				      	    			timer: 2000, 
    	       										closeOnConfirm : true
    	       									}, function() {
    	       										window.location.reload();//刷新当前页面
    	       									});
    	       								} else {
    	       									swal("错误", data.message, "error");
    	       								}  
    	       							}
    	       						});
    	       					}
    						}
    	       			});
    					} else{ 
    						swal({
           		    			title:"即将进入下一环节",
           		    			text: "1秒后自动关闭。", 
           		    			timer: 1000, 
           					    showConfirmButton: false
           		    		});
    						openyem("添加面试记录", "<%=contextPath%>/demandInterview/addView?communicateId=" + id +"&recommendId=" + recommendId, 500, 550);
    						
    					} 
    				})
    	}
    	function addresult(id,recommendId,companyId,demandId,talentsId) {
    		swal({ 
    			title: "该人才是否通过？", 
    			type: "warning", 
    			showCancelButton: true, 
    			confirmButtonColor: "#DD6B55", 
    			confirmButtonText: "No", 
    			cancelButtonText: "Yes", 
    			closeOnConfirm: false, 
    			closeOnCancel: false 
    			}, 
    			function(isConfirm) { 
    				if (isConfirm) { 
    					swal({
       		    			title:"即将进入下一环节",
       		    			text: "1秒后自动关闭。", 
       		    			timer: 1000, 
       					    showConfirmButton: false
       		    		});
    					openyem("反馈推荐结果", "<%=contextPath%>/recommendResult/addView?recommendId=" + recommendId+"&communicateId="+id, 600, 500);
    					} else{ 
    						swal({
           		    			title:"即将进入下一环节",
           		    			text: "1秒后自动关闭。", 
           		    			timer: 1000, 
           					    showConfirmButton: false
           		    		});
    						openyem("添加沟通记录", "<%=contextPath%>/demandCommunicate/addView?communicateId=" + id +"&talentsId=" + talentsId+"&recommendId=" + recommendId +"&companyId=" + companyId+"&demandId="+demandId, 500, 550);
    						
    					} 
    				})
    	}
    	function openrecord(id) {
    		openyem("查看面试记录", "<%=contextPath%>/demandInterview/list?communicateId=" + id, 850, 750);
    	}
    	
    	function addsurvey(id,recommendId) {
    		swal({ 
    			title: "是否背景调查？", 
    			type: "warning", 
    			showCancelButton: true, 
    			confirmButtonColor: "#DD6B55", 
    			confirmButtonText: "No", 
    			cancelButtonText: "Yes", 
    			closeOnConfirm: false, 
    			closeOnCancel: false 
    			}, 
    			function(isConfirm) { 
    				if (isConfirm) { 
    					swal({
       		    			title:"即将进入下一环节",
       		    			text: "1秒后自动关闭。", 
       		    			timer: 1000, 
       					    showConfirmButton: false
       		    		});
    					openyem("反馈调查结果", "<%=contextPath%>/recommendResult/addView?recommendId=" + recommendId+"&communicateId="+id, 600, 500);
    					} else{ 
    						swal({
           		    			title:"即将进入下一环节",
           		    			text: "1秒后自动关闭。", 
           		    			timer: 1000, 
           					    showConfirmButton: false
           		    		});
    						openyem("添加背景调查", "<%=contextPath%>/demandInvestigation/addView?communicateId=" + id +"&recommendId="+recommendId, 800, 750);
    						
    					} 
    				})
    	}
    	function addoffer(id,recommendId) {
    		openyem("添加offer记录", "<%=contextPath%>/demandOfferRecord/addView?communicateId=" + id +"&recommendId="+recommendId, 800, 550);
    	}
    	function addentry(id,recommendId) {
    		openyem("添加入职记录", "<%=contextPath%>/demandOfferRecord/addView?communicateId=" + id +"&recommendId="+recommendId, 800, 550);
    	}
    	function addinvoice(id,demandId,talentsId) {
    		openyem("添加开票信息", "<%=contextPath%>/invoice/addView?communicateId=" + id+"&demandId=" + demandId+"&talentsId="+talentsId, 1080, 720);
    	}
    	function openrecord(id) {
    		openyem("查看面试记录", "<%=contextPath%>/demandInterview/list?communicateId=" + id, 850, 750);
    	}
    	function updateStatus(id,status){
    		$.ajax({
    			url:'<%=contextPath%>/demandCommunicate/updateStatus',
    			data:{
    				"id":id,
    				"ispast":status
    			},
   				type : 'post',
   				dataType : "json",
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					} 
				}
    		});
    	}
</script>
</body>
</html>

